import React, { FC } from "react";
import { Navigate } from "react-router-dom";
import { useAppSelector } from "@/app/hooks";

function withAuthorization(WrappedComponent: FC) {
	return () => {
		const name = useAppSelector((state) => state.user.name);

		if (!name) {
			return <Navigate to="/login" />;
		}

		return <WrappedComponent />;
	};
}

export default withAuthorization;
